import {messages} from "share/common";
import httpFetch from "share/httpFetch";
import config from "config";
import errorMessage from "share/errorMessage";
import {commonBarReportFactory} from "../echarts-data-transfer";

export default {
  //超标金额-费用类型分析top50
  getExcessExpenseReport(params) {
    return new Promise((resolve, reject) => {
      httpFetch.post(config.baseUrl + '/report/api/exp/excess/exp/search', params)
        .then((response) => {
          let res = {};
          let data = response.data || [];
          res.dataLength = data.length;
          res.options = commonBarReportFactory(data, 1, undefined, true);
          res.options.series[0].name = messages('finance-7.key310')/*金额(元)*/;
          res.options.legend.data = [messages('finance-7.key310')/*金额(元)*/];
          resolve(res);
        })
        .catch((err) => {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },
  //超标金额-人员分析top50
  getExcessUserReport(params) {
    return new Promise((resolve, reject) => {
      httpFetch.post(config.baseUrl + '/report/api/exp/excess/user/search', params)
        .then((response) => {
          let res = {};
          let data = response.data || [];
          res.dataLength = data.length;
          res.options = commonBarReportFactory(data, 1, undefined, true);
          res.options.series[0].name = messages('finance-7.key310')/*金额(元)*/;
          res.options.legend.data = [messages('finance-7.key310')/*金额(元)*/];
          resolve(res);
        })
        .catch((err) => {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },
  // 未超标金额-费用类型分析
  getNotExcessExpenseReport(params) {
    return new Promise((resolve, reject) => {
      httpFetch.post(config.baseUrl + '/report/api/exp/excess/exp/not/search', params)
        .then((response) => {
          let res = {};
          let data = response.data || [];
          res.dataLength = data.length;
          res.options = commonBarReportFactory(data, 0, undefined, true);
          res.options.series[0].name = messages('finance-7.key310')/*金额(元)*/;
          res.options.legend.data = [messages('finance-7.key310')/*金额(元)*/];
          resolve(res);
        })
        .catch((err) => {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },
  // 未超标金额-人员分析
  getNotExcessUserReport(params) {
    return new Promise((resolve, reject) => {
      httpFetch.post(config.baseUrl + '/report/api/exp/excess/user/not/search', params)
        .then((response) => {
          let res = {};
          let data = response.data || [];
          res.dataLength = data.length;
          res.options = commonBarReportFactory(data, 0, undefined, true);
          res.options.series[0].name = messages('finance-7.key310')/*金额(元)*/;
          res.options.legend.data = [messages('finance-7.key310')/*金额(元)*/];
          resolve(res);
        })
        .catch((err) => {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  },
  //合规明细统计表
  getUserFeeDetailReport(params, pagination){
    return new Promise((resolve, reject) => {
      httpFetch.post(config.baseUrl + '/report/api/exp/excess/detail' + '?page=' + pagination.page + "&size=" + pagination.size, params)
        .then((response) => {
          response.data = response.data.filter(item => {
            if (item + "" !== "null" && item + "" !== "undefined") {
              return item;
            }
          })
          resolve(response)
        })
        .catch((err) => {
          errorMessage(err.response);
          reject(err.response);
        })
    })
  }
}
